package cn.zero._01_sync;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception {
        //1.创建生产者对象,并指定生产者组名
        DefaultMQProducer producer = new DefaultMQProducer("producer_hello_group");
        //2.连接nameserver
        producer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动生产者
        producer.start();
        //3.创建消息对象
        Message message = new Message("producer", "hello", "我在源码学习Java！".getBytes(StandardCharsets.UTF_8));
        //4.发送消息
        SendResult sendResult = producer.send(message);
        //4.3.打印消息发送结果
        System.out.println(sendResult);
        //5.关闭生产者
        producer.shutdown();
    }
}
